package com.jsd2412.backend.bed.controller;

import com.jsd2412.backend.base.response.JsonResult;
import com.jsd2412.backend.bed.pojo.dto.*;
import com.jsd2412.backend.bed.pojo.vo.BedVO;
import com.jsd2412.backend.bed.service.BedService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "床位管理")
@RestController
@RequestMapping("/v1/bed/")
@Slf4j
public class BedController {
    @Autowired
    private BedService bedService;

    @GetMapping("select")
    public JsonResult select(BedQuery bedQuery) {
        log.debug("查询床位业务:{}", bedQuery);
        List<BedVO> list = bedService.select(bedQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(BedSaveParam bedSaveParam) {
        log.debug("保存床位业务:{}", bedSaveParam);
        bedService.save(bedSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Integer id) {
        log.debug("删除床位业务:{}", id);
        bedService.delete(id);
        return JsonResult.ok();
    }

    @GetMapping("selectBedCard")
    public JsonResult selectBedCard(BedQuery bedQuery) {
        log.debug("查询床位卡片信息:{}", bedQuery);
        List<BedVO> list = bedService.selectBedCard(bedQuery);
        return JsonResult.ok(list);
    }

    @GetMapping("selectEmptyBedList")
    public JsonResult selectEmptyBedList(BedQuery bedQuery) {
        log.debug("查询指定房间空床:{}", bedQuery);
        List<BedVO> list = bedService.selectEmptyBedList(bedQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("turnRoom")
    public JsonResult turnRoom(BedTurnParam bedTurnParam) {
        log.debug("转房:{}", bedTurnParam);
        bedService.turnRoom(bedTurnParam);
        return JsonResult.ok();
    }

    @PostMapping("toEmpty")
    public JsonResult toEmpty(BedToEmptyParam bedToEmptyParam) {
        log.debug("床位置空:{}", bedToEmptyParam);
        bedService.toEmpty(bedToEmptyParam);
        return JsonResult.ok();
    }

    @PostMapping("allocation")
    public JsonResult allocation(BedAllocationParam bedAllocationParam) {
        log.debug("床位分配");
        bedService.allocation(bedAllocationParam);
        return JsonResult.ok();
    }

    @GetMapping("getBedTotalByRoom")
    public JsonResult getBedTotalByRoom(String roomNumber) {
        log.debug("获取当前房间的床位总数:{}", roomNumber);
        int BedTotal = bedService.getBedTotalByRoom(roomNumber);
        return JsonResult.ok(BedTotal);
    }

    @GetMapping("selectBedList")
    public JsonResult selectBedList(BedQuery bedQuery) {
        log.debug("查询床位设置页显示的列表数据:{}", bedQuery);
        List<BedVO> list = bedService.selectBedList(bedQuery);
        return JsonResult.ok(list);
    }
}
